package com.zp.imagecompresspractice.View;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v13.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;

import com.zp.imagecompresspractice.R;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by izp on 2017/7/16.
 */

public class TabViewActivity extends AppCompatActivity {
    private TabView mTabView;
    private ViewPager mViewPager;
    private List<String> mTitles = Arrays.asList("郑威","逍遥","曾菁","张小豪","刘亦菲","张含韵","张泽天","游园","孟庆瑞");
    private List<Fragment> mTabFragments = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_tab_view);
        mTabView = (TabView) findViewById(R.id.tab);
        mViewPager = (ViewPager) findViewById(R.id.viewPager);
        for (String title : mTitles){
            TabFragment fragment = TabFragment.newInstance(title);
            mTabFragments.add(fragment);
        }
        FragmentPagerAdapter pagerAdapter = new FragmentPagerAdapter(getFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return mTabFragments.get(position);
            }

            @Override
            public int getCount() {
                return mTabFragments.size();
            }
        };

        mTabView.setTabItemTitle(mTitles);
        mViewPager.setAdapter(pagerAdapter);
        mTabView.bindWithViewPager(mViewPager,0);

    }
}
